package com.cosytek.farmmanager.data;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Happy on 2015/4/19.
 */
public class FarmSummary {
    private String id;
    private String name;
    private int planCount;
    private int taskCount;

    private FarmSummary(){}

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getPlanCount() {
        return planCount;
    }

    public int getTaskCount() {
        return taskCount;
    }

    public static FarmSummary createFromJSONObject(JSONObject jsonObject) {
        FarmSummary fs = new FarmSummary();
        if (fs.refreshFromJSONObject(jsonObject)) {
            return fs;
        }
        return null;
    }

    private boolean refreshFromJSONObject(JSONObject jsonObject) {
        try {
            id = jsonObject.getString("id");
            name = jsonObject.getString("name");
            taskCount = jsonObject.getInt("taskcount");
            planCount = jsonObject.getInt("plancount");

            return true;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return false;
    }
}
